package me.haoliang.repository.impl

import java.util
import javax.annotation.Resource

import me.haoliang.repository.Repository
import org.springframework.beans.factory.annotation.Autowired
import tk.mybatis.mapper.common.Mapper


/**
  * author: planck 
  * createTime: 2016/11/11.
  */
class BaseRepository[T](@Autowired protected val mapper: Mapper[T]) extends Repository[T]{

  override def selectByKey(key: Object): T = {
    return mapper.selectByPrimaryKey(key)
  }

  override def save(t: T): Int = {
    return mapper.insert(t)
  }

  override def delete(key: Object): Int = {
    return mapper.deleteByPrimaryKey(key)
  }

  override def updateAll(t: T): Int = {
    return mapper.updateByPrimaryKey(t)
  }

  override def updateNotNull(t: T): Int = {
    return mapper.updateByPrimaryKeySelective(t)
  }

  override def selectBtExample(example: Object): util.List[T] = {
    return  mapper.selectByExample(example)
  }
}
